package com.example.base.job;

import org.quartz.*;
import org.springframework.stereotype.Component;

/**
 * @Classname JobListenerServer
 * @Description TODO
 * @Date 2023/1/12 16:02
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@Component
public class JobListenerServer implements JobListener {


    @Override
    public String getName() {
        String name = getClass().getSimpleName();
        return name;
    }

    /**
     * 开始执行
     * @param jobExecutionContext
     */
    @Override
    public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
        JobDataMap jobDataMap=jobExecutionContext.getJobDetail().getJobDataMap();
    }

    /**
     * 执行异常
     * @param jobExecutionContext
     */
    @Override
    public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
        JobDataMap jobDataMap=jobExecutionContext.getJobDetail().getJobDataMap();
    }



    /**
     * 执行完毕
     * @param jobExecutionContext
     * @param e
     */
    @Override
    public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
        JobDataMap jobDataMap=jobExecutionContext.getJobDetail().getJobDataMap();
//        SysJob sysJob=(SysJob) jobDataMap.get("sysjob");
//        Sysjoblog sysjoblog=new Sysjoblog();
//        sysjoblog.setJobname(sysJob.getJobname());
//        sysjoblog.setClazz(sysJob.getClazz());
//        sysjoblog.setMethode(sysJob.getMethodName());
//        sysjoblog.setJobId(sysJob.getId());
//        sysjoblog.setCratetime(new Date());
//        service.save(sysjoblog);
    }

    /**
     * 获取下次执行时间
     * @param cron
     * @return
     */
    private CronExpression getCronByString(String cron){
        try {
            return new CronExpression(cron);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
